//
//  MessageListTabCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2018/1/8.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "MessageListTabCell.h"

@interface MessageListTabCell ()
@property (weak, nonatomic) IBOutlet UIView *yellowView;

@property (weak, nonatomic) IBOutlet UIView *timeBgView;

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lastMargin;

@property (weak, nonatomic) IBOutlet UILabel *middleTitleLabel;

@property (weak, nonatomic) IBOutlet UIView *conrBgView;

@property (weak, nonatomic) IBOutlet UIView *midddleBgView;

@property (weak, nonatomic) IBOutlet UILabel *bottomLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *middleMargin;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleBGH;

@end

@implementation MessageListTabCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.contentView.backgroundColor = randomColor;
    
    self.bottomMargin.constant = 0;
    
    self.middleMargin.constant = 20;
    
    self.bottomLabel.backgroundColor = [UIColor whiteColor];
    
    self.timeBgView.backgroundColor = viewBgGrey;
    
    self.timeLabel.font = MYFONT(14);
    
    self.conrBgView.backgroundColor = [UIColor whiteColor];
    
    self.conrBgView.layer.cornerRadius = 8;
    
    self.conrBgView.layer.masksToBounds = YES;
    
    self.midddleBgView.backgroundColor = [UIColor whiteColor];
    
    self.middleTitleLabel.font = MYFONT(16);
    
    self.middleTitleLabel.textColor = themeColor;
    
    self.lastMargin.constant = 5;
    
    self.bottomLabel.font = MYFONT(15);
    
    self.bottomLabel.textColor = darkGray;
    
    self.timeLabel.textColor = darkGray;
    
    self.yellowView.backgroundColor = viewBgGrey;
    
    
    self.bottomLabel.text = @"";
    
//    self.titleBGH.constant = 20;
//    self.midddleBgView.hidden = YES;
}

- (void)setModel:(SysMessageModel *)model{
    
    _model = model;
    
    self.timeLabel.text = _model.jpush_addtime;
    
    if ([_model.jpush_type isEqualToString:@"1"]) {
        
        self.middleTitleLabel.text = @"缴费回执";
        
    } else if ([_model.jpush_type isEqualToString:@"2"]) {
        
        self.middleTitleLabel.text = @"订单发货";

    }else if ([_model.jpush_type isEqualToString:@"3"]) {
        
        self.middleTitleLabel.text = @"订单退款";

    }else if ([_model.jpush_type isEqualToString:@"4"]){
        
        self.middleTitleLabel.text = @"资讯";

        
    }else{
        
        self.middleTitleLabel.text = @"系统消息";
        
    }
    
    self.bottomLabel.attributedText = [self attributedString:_model.jpush_content withFont:MYFONT(15)];

}




- (NSAttributedString *)attributedString:(NSString *)str withFont:(UIFont *)font{
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:str];
    
    [attr addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, str.length)];
    [attr addAttribute:NSKernAttributeName value:@(1.0f) range:NSMakeRange(0, str.length)];
    
    NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc]init];
    
    para.lineSpacing = 1;
    
    para.firstLineHeadIndent = 20;
    
    [attr addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, str.length)];
    
    return attr;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
